package me.wpf.DesignMode.singleton;

/**
 * Description:懒汉式 ,枚举实现,不会被反射破坏单例
 *
 * @author 王朋飞
 * @create 2019/5/5
 */
public class Singleton3 {

    private Singleton3(){}

    public static Singleton3 getInstance(){
        return SingletonHolder.INSTANCE.getInstance();
    }

    /**
     * JVM会保证enum不能被反射并且构造器方法只执行一次；
     */
    private static enum  SingletonHolder{
        INSTANCE;

        private Singleton3 singleton3;

        private SingletonHolder(){
            singleton3 = new Singleton3();
        }

        public Singleton3 getInstance(){
            return singleton3;
        }
    }
}
